package ac.incheon.cns;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ThirdViewCustomAdapter extends BaseAdapter {

	private Context mContext;
	private List<ThirdViewListViewModel> mListArray;
	private LayoutInflater mInflater;

	public ThirdViewCustomAdapter(Context context,
			ArrayList<ThirdViewListViewModel> objects) {
		this.mContext = context;
		this.mListArray = objects;
		this.mInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return mListArray.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mListArray.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		ThirdViewListViewModel model = mListArray.get(position);

		if (convertView == null) {
			convertView = mInflater.inflate(
					R.layout.activity_third_view_listview_row, null);
		}

		if (model != null) {
			TextView name = (TextView) convertView
					.findViewById(R.id.listview_row_name);
			name.setText(model.getName());
			TextView phone = (TextView) convertView
					.findViewById(R.id.listview_row_phone);
			phone.setText(model.getPhone());
			TextView comment = (TextView) convertView
					.findViewById(R.id.listview_row_comment);
			comment.setText(model.getComment());
		}

		return convertView;

	}
}
